# -*- coding: utf-8 -*-
"""
@Project ：dz-at-web
@File    ：fun_reset_pwd.py
@Author  ：王涛
@Date    ：2021/8/28 16:07
"""

import allure
from common.page import Page
from common.utils import Utils
from config.config import Config
from dz_service.page_elements.el_login import login
from dz_service.page_elements.el_reset_pwd import reset_pwd
from dz_service.page_elements.el_common import common
from dz_service.function.fun_common import Common
from time import sleep


class ResetPwd:

    def click_sure(self):
        Page.click(common, '公共页面', '确定', is_els=True, num=0)

    def click_alert(self):
        Page.click(reset_pwd, '密码重置页面', '确定', is_els=True, num=0)

    # def start_record(self, video_path):
      # Page.send_key(common, '公共页面', '开始录制', video_path)

    @allure.step('step2:需要重置的资金号和手机号校验')
    def check_reset_pwd_page(self, client_id, phone, id_card, account_vf_code):
        Page.click(login, '登录页面', '密码重置')
        Page.send_key(reset_pwd, '密码重置页面', '资金账号', client_id)
        Page.send_key(reset_pwd, '密码重置页面', '身份证号码', id_card)
        Page.send_key(reset_pwd, '密码重置页面', '图形验证码', account_vf_code)
        Page.send_key(reset_pwd, '密码重置页面', '手机号', phone)
        Page.click(reset_pwd, '密码重置页面', '获取短信验证码')
        Page.send_key(reset_pwd, '密码重置页面', '输入短信验证码', Utils.get_sms_code())
        Common().click_next()

    @allure.step('step3:重置密码资料完整性检查')
    def reset_pwd(self, positive_pic, back_pic, head_pic, video):
        # 密码重置页面
        positive_pic_path = Utils.get_test_pic(positive_pic)
        back_pic_path = Utils.get_test_pic(back_pic)
        head_pic_path = Utils.get_test_pic(head_pic)
        video_path = Utils.get_test_pic(video)
        # 资料完整性检查
        assert Page.element(reset_pwd, "检查元素", "资料完整").text == "资料完整", "页面文字：资料完整 检验失败。"
        assert Page.element(reset_pwd, "检查元素", "风险测评未过期").text == "风险测评未过期", "页面文字：风险测评未过期 检验失败。"
        Common().click_next()
        # 办理重置
        assert Page.element(reset_pwd, "检查元素", "密码重置").text == "密码重置", "页面文字：密码重置 检验失败。"
        Common().click_handle_now()
        # 办理条件检查
        assert Page.element(reset_pwd, "检查元素", "您符合名单办理要求").text == "您符合名单办理要求", "页面文字：您符合名单办理要求 检验失败。"
        assert Page.element(reset_pwd, "检查元素", "此账户开户证件为身份证").text == "此账户开户证件为身份证", "页面文字：此账户开户证件为身份证 检验失败。"
        Common().click_next()
        # 上传身份信息
        Common().upload_id_card_pic(positive_pic_path, back_pic_path, head_pic_path)
        self.click_sure()
        # 弹窗处理
        if Config().env == 'test':
            self.click_alert()
        else:
            assert True
        # 上传录制视频
        Page.check_page_loading(10)
        #self.start_record(video_path)
        Page.send_key(common, '公共页面', '开始录制', video_path)
        sleep(3)
        self.click_alert()
        sleep(1)

    @allure.step('step4:更新密码')
    def update_pwd(self, pwd):
        Page.send_key(reset_pwd, '设置密码页面', '请输入6位数字密码', pwd)
        Page.send_key(reset_pwd, '设置密码页面', '请再次输入密码', pwd)
        Page.click(common, '公共页面', '提交')
        Page.check_page_loading(5)
        assert Page.element(reset_pwd, "检查元素", "提交成功").text == "提交成功", "页面文字：提交成功 检验失败。"
        Page.logger.info('提交成功。', extra={'appname': 'update_pwd'})